﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
	/// <summary>
	/// 场景NPC配置脚本
	/// </summary>
	[ExecuteInEditMode]
	public class SceneNPC : SceneObject
	{
#if UNITY_EDITOR
		[Header("Npc.xml表格ID")]
		[SerializeField]
		private int npcId;

		[Header("预览NPC资源")]
		[SerializeField]
		private AssetID previewAssetId;

		private GameObject previewPrefab;

		[Header("客户端模拟的可移动的NPC")]
		[SerializeField]
		private bool isWalking;

		[Header("NPC移动的路径点")]
		[Tooltip("xy再场景网格视图上的OutputFocusPos:属性查看当前刷子所再的位置进行设置。")]
		[SerializeField]
		private Vector2[] paths;


		public int ID { get { return this.npcId; } }
		public bool IsWalking { get { return isWalking; } }

		public Vector2[] Paths { get { return paths; } }

		protected override bool HasPreview()
        {
			return this.previewPrefab != null;
        }

        protected override GameObject BuildPreview()
        {
			return Instantiate(this.previewPrefab);
        }



		void OnValidate()
        {
			if (Application.isPlaying) return;
			this.name = "NPC" + this.npcId;
			if(!string.IsNullOrEmpty(previewAssetId.AssetGUID))
            {
				this.previewPrefab = previewAssetId.LoadObject<GameObject>();
            }
            else
            {
				//Debug.LogWarning("Can not find NPC with id: " + this.npcId);
				this.previewPrefab = null;
			}
			this.RefreshPreview();
		}

#endif
	}
}

